﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using FIFP.DashBoard.Model;
using FIFP.DashBoard.Helper;
using System.Linq;

namespace FIFP.DashBoard.Calculation
{
    public class CalculationHelper
    {
        public static List<Unit> getWaterModules(List<Unit> allUnitList)
        {
            return (from item in allUnitList
                    where item.UnitType == FIFPConstants.UNITTYPE_MODULE
                    select item).ToList<Unit>();
        }

        public static Unit getWIP(List<Unit> allUnitList)
        {
            List<Unit> wIPUnitsList = (from item in allUnitList
                                       where item.UnitName == "WIP"
                                       select item).ToList<Unit>();
            if (wIPUnitsList != null && wIPUnitsList.Count > 0)
                return wIPUnitsList[0];
            else
                return null;
        }

        public static Unit getCP1(List<Unit> allUnitList)
        {
            List<Unit> wIPUnitsList = (from item in allUnitList
                                       where item.UnitName == "CP1"
                                       select item).ToList<Unit>();
            if (wIPUnitsList != null && wIPUnitsList.Count > 0)
                return wIPUnitsList[0];
            else
                return null;
        }

        public static Unit getUSOSSP(List<Unit> allUnitList)
        {
            List<Unit> wIPUnitsList = (from item in allUnitList
                                       where item.UnitName == "USOSSP"
                                       select item).ToList<Unit>();
            if (wIPUnitsList != null && wIPUnitsList.Count > 0)
                return wIPUnitsList[0];
            else
                return null;
        }

        public static Unit getByPass(List<Unit> allUnitList)
        {
            List<Unit> bypasslineList = (from item in allUnitList
                                        where item.UnitName == "US Oil Bypass"
                                        select item).ToList<Unit>();
            if (bypasslineList != null && bypasslineList.Count > 0)
                return bypasslineList[0];
            else
                return null;

        }

        public static List<Unit> getWaterStrings(List<Unit> allUnitList)
        {
            return (from item in allUnitList
                    where item.UnitType == FIFPConstants.UNITTYPE_STRING && item.FluidType == FIFPConstants.FLUIDTYPE_WATER
                    select item).ToList<Unit>();
        }

        public static List<Unit> getWaterRadials(List<Unit> allUnitList)
        {
            return (from item in allUnitList
                    where item.UnitType == FIFPConstants.UNITTYPE_RADIAL && item.FluidType == FIFPConstants.FLUIDTYPE_WATER
                    select item).ToList<Unit>();
        }

        public static List<Unit> getGasCompressors(List<Unit> allUnitList)
        {
            return (from item in allUnitList
                    where item.UnitType == FIFPConstants.UNITTYPE_COMPRESSOR
                    select item).ToList<Unit>();
        }

        public static List<Unit> getAutoInjectionTowers(List<Unit> allUnitList)
        {
            return (from item in allUnitList
                    where item.UnitType == FIFPConstants.UNITTYPE_TOWER && item.FluidType == FIFPConstants.FLUIDTYPE_GAS && item.ParentUnitID == -2
                    select item).ToList<Unit>();
        }

        public static List<Unit> getGasTowers(List<Unit> allUnitList)
        {
            return (from item in allUnitList
                    where item.UnitType == FIFPConstants.UNITTYPE_TOWER && item.FluidType == FIFPConstants.FLUIDTYPE_GAS
                    select item).ToList<Unit>();
        }

        public static List<Unit> getGasPipelines(List<Unit> allUnitList)//Since Changed radial to pipeline in database need to do the corresponding changes here - Dhilip-18-05-2013
        {
            return (from item in allUnitList
                    where item.UnitType == FIFPConstants.UNITTYPE_PIPELINE && item.FluidType == FIFPConstants.FLUIDTYPE_GAS
                    select item).ToList<Unit>();
        }

        public static List<Unit> getOilStrings(List<Unit> allUnitList)
        {
            return (from item in allUnitList
                    where item.UnitType == FIFPConstants.UNITTYPE_STRING && item.FluidType == FIFPConstants.FLUIDTYPE_OIL
                    select item).ToList<Unit>();
        }

        public static List<Unit> getOilRadials(List<Unit> allUnitList)
        {
            return (from item in allUnitList
                    where item.UnitType == FIFPConstants.UNITTYPE_RADIAL && item.FluidType == FIFPConstants.FLUIDTYPE_OIL
                    select item).ToList<Unit>();
        }

        public static List<Unit> getSeperators(List<Unit> allUnitList)
        {
            return (from item in allUnitList
                    where item.UnitType == FIFPConstants.UNITTYPE_SEPERATOR
                    select item).ToList<Unit>();
        }

        public static List<Unit> getCSPSeperators(List<Unit> allUnitList)
        {
            return allUnitList.Where(s => s.UnitName == FIFPConstants.PLATFORM_CSP_UNIT && s.ChildUnitList != null).SelectMany(s => s.ChildUnitList).ToList<Unit>();
        }

        public static List<Unit> getCSP1Seperators(List<Unit> allUnitList)
        {
            return allUnitList.Where(s => s.UnitName == FIFPConstants.PLATFORM_CSP_1_UNIT && s.ChildUnitList != null).SelectMany(s => s.ChildUnitList).ToList<Unit>();
        }

    }
}
